<%@ page import="com.fjrcloud.entity.Land" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>房屋装修成新</title>

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${path}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${path}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${path}/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${path}/css/animate.css" rel="stylesheet">
    <link href="${path}/css/style.css?v=4.1.0" rel="stylesheet">

    <style>
        .complete {
            background-color: #1ab394;
            color: #FFFFFF;
        }
        .incomplete {
            background-color: #f8ac59;
            color: #FFFFFF;
        }
    </style>
</head>

<body class="gray-bg">

    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12 animated fadeInRight">

                <div class="ibox">
                    <div class="ibox-title">
                        <h5>房屋二次装修成新率标准</h5>
                        <div class="ibox-tools">
                            <button class="btn btn-primary btn-xs add">创建标准</button>
                        </div>
                    </div>
                    <div class="ibox-content">

                        <div class="project-list">

                            <table class="table table-hover">
                                <tbody>
                                <c:forEach items="${intoNews }" var="item">
                                    <tr data-id="${item.id}">
                                        <td class="project-title"><span>${item.name }</span></td>
                                        <td class="project-completion"><small>${item.ratio }%</small></td>
                                        <td class="project-actions">
                                            <a href="#" class="btn btn-white btn-sm delete"><i class="fa fa-trash"></i> 删除 </a>
                                            <a href="#" class="btn btn-white btn-sm update"><i class="fa fa-pencil"></i> 编辑 </a>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="${path}/js/jquery.min.js?v=2.1.4"></script>
    <script src="${path}/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${path}/js/plugins/layer/layer.min.js"></script>
    <!-- iCheck -->
    <script src="${path}/js/plugins/iCheck/icheck.min.js"></script>
    <!-- 自定义js -->
    <script src="${path}/js/content.js?v=1.0.0"></script>
    <script src="${path}/js/jquery.form.js"></script>


    <script>

        function addHtml() {
            var html ='\
                    <div class="ibox-content" style="overflow: hidden;height: 100%;">\
                        <form class="form-horizontal" method="post">\
                            <input type="text" name="id" style="display: none;">\
                            <div class="form-group">\
                                <label class="col-sm-2 control-label">名称：</label>\
                                <div class="col-sm-10"><input type="text" class="form-control" name="name"></div>\
                            </div>\
                            <div class="form-group">\
                                <label class="col-sm-2 control-label">单价：</label>\
                                <div class="col-sm-10">\
                                    <div class="input-group">\
                                        <input type="number" min=0 class="form-control" name="ratio"> <span class="input-group-addon">%</span>\
                                    </div>\
                                </div>\
                            </div>\
                            <div class="form-group">\
                                <label class="col-sm-2 control-label">描述：</label>\
                                <div class="col-sm-10">\
                                    <textarea class="form-control" style="resize:none" name="description"></textarea>\
                                </div>\
                            </div>\
                        </form>\
                    </div>';

            return html;
        }

        $(document).ready(function(){
            $('.add').click(function () {

                layer.open({
                    type: 1,
                    area: ['600px','auto'],
                    content: addHtml(),
                    btn:['保存','取消'],
                    success:function (layero, index) {},
                    yes: function(index, layero){

                        var options ={
                            type: "post",
                            url: "${path}/api/housing/decorate/intoNew/save",
                            dataType: "json",
                            uploadProgress: function (event, position, total, percentComplete) {},
                            success: function (result) {
                                if (result.code == "${result_success}") {
                                    layer.msg("保存成功");
                                    location.reload();
                                    layer.close(index);
                                }else {
                                    layer.msg(result.data);
                                }
                            }
                        };

                        $(layero).find('form').ajaxSubmit(options);

                        layer.close(index);
                    }
                });
            });

            $('.update').click(function () {

                var id = $(this).parents('tr').attr('data-id');

                $.post(
                    "${path}/api/housing/decorate/intoNew/get",
                    {id:id},
                    function (result) {
                        if (result.code == "${result_success}") {

                            layer.open({
                                type: 1,
                                area: ['600px','auto'],
                                content: addHtml(),
                                btn:['保存','取消'],
                                success:function (layero, index) {

                                    $(layero).find('input[name="name"]').val(result.data.name);
                                    $(layero).find('input[name="ratio"]').val(result.data.ratio);
                                    $(layero).find('textarea[name="description"]').val(result.data.description);
                                    $(layero).find('input[name="id"]').val(result.data.id);

                                },
                                yes: function(index, layero){

                                    var options ={
                                        type: "post",
                                        url: "${path}/api/housing/decorate/intoNew/save",
                                        dataType: "json",
                                        uploadProgress: function (event, position, total, percentComplete) {},
                                        success: function (result) {
                                            if (result.code == "${result_success}") {
                                                location.reload();
                                                layer.close(index);
                                            }else {
                                                layer.msg(result.data);
                                            }
                                        }
                                    };

                                    $(layero).find('form').ajaxSubmit(options);

                                    layer.close(index);
                                }
                            });
                        }else {
                            layer.msg(result.data);
                        }
                    },
                    'json'
                );
            });

            $('.delete').click(function () {

                $(this).find('tr').attr('data-id');

                var id = $(this).parents('tr').attr('data-id');

                $.post(
                    "${path}/api/housing/decorate/intoNew/del",
                    {id:id},
                    function (result) {
                        if (result.code == "${result_success}") {
                            location.reload();
                        }else {
                            layer.msg(result.data);
                        }
                    },
                    'json'
                );
            });

        });

    </script>

    </body>
</html>
